<?php

namespace app\common\validate\shop;

use app\common\validate\BaseValidate;

class GoodsValidate extends BaseValidate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'category_id|分类' => 'require|min:1|checkCategory',
        'name|牛名称' => 'require|length:2,200',
        'code|编号' => 'require|length:2,200',
        'enname|英文名称' => 'require|length:2,200',
        'status|是否上架' => 'require|in:0,1',
        'thumb|展示图' => 'require|length:2,255',
        'pics|图册' => 'require',
        'money|价格' => 'require|number|egt:0',
        'stock|库存' => 'require|egt:0',
        'gtpi|gtpi值' => 'require|number',
        'real_money|净效应指数' => 'require|number',
        'milk_pro|产奶育种值' => 'require|number',
        'breast|乳房指数' => 'require|number',
        'foot|肢蹄指数' => 'require|number',
        'beast|公牛配种难产率' => 'require|number',
        'year|生产寿命' => 'require|number',
        'birth|女儿妊娠率' => 'require|number',

    ];
    /**
     * 提示消息
     */
    protected $message = [
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];


    protected function checkCategory($value) {
        $info = \app\common\model\shop\Category::get($value);
        if (!$info) {
            return '商品分类传递错误';
        }

        return true;
    }
    
}
